﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ewts.Storage
{
    public partial class CargoHandling : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                PageClear();
            }
        }

        protected void BindDataUp(string loadID)
        {
            string where = "loadnumid = '" + loadID + "' and status = '1' or loadnumid = '" + loadID + "' and status = '2'";
            DataTable dt = new DataLib.BLL.BarCode().GetList(where).Tables[0];
            reptCargo1.DataSource = dt;
            reptCargo1.DataBind();

        }

        protected void BindDataDown(string loadID)
        {
            string where = "loadnumid = '" + loadID + "' and status = '3' or loadnumid = '" + loadID + "' and status = '4'";
            DataTable dt = new DataLib.BLL.BarCode().GetList(where).Tables[0];
            reptCargo2.DataSource = dt;
            reptCargo2.DataBind();
            
        }

        protected void btnAcquire_Click(object sender, EventArgs e)
        {
            string loadNum = txtLoadNum.Text;
            if (loadNum != null && loadNum.Trim() != "")
            {
                DataSet ds = new DataLib.BLL.LoadNum().GetList("loadnum ='" + loadNum + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    BindDataUp(ds.Tables[0].Rows[0]["id"].ToString());
                    BindDataDown(ds.Tables[0].Rows[0]["id"].ToString());
                }
                else
                {
                    PageClear();
                }
            }
            else
            {
                PageClear();
            }
        }

        protected string GetLoadNum(string loadID)
        {
            DataLib.Model.LoadNum loadModel = new DataLib.BLL.LoadNum().GetModel(int.Parse(loadID));
            return loadModel.loadnum;
        }

        protected void PageClear()
        {
            reptCargo1.DataSource = "";
            reptCargo1.DataBind();
            reptCargo2.DataSource = "";
            reptCargo2.DataBind();
        }
    }
}